import React, { Component } from 'react'
import{Router,Route,Switch,Redirect}from 'react-router-dom'
import LoginPage from '@src/pages/loginPage/index'
import { createBrowserHistory } from "history";
import Layout from './shared/layout';
import DashboardPage from './pages/dashboardPage';
import RouteGuard from './shared/routeGuard';
import isLogin from './utils/isLogin';


export const history = createBrowserHistory()

export default class App extends Component {



  render() {
    return (
      <Router history={history}>
        <Switch>
          <Redirect from='/' to='/login' exact />
          <Route path='/login' component={LoginPage}/>
          <Route path='/admin'>
          <RouteGuard guards={[isLogin]} onRejected={() => <Redirect to="/login" push={false} />}>
            <Layout>
                  <Switch>
                      <Redirect from='/admin' to='/admin/dashboard' exact/>
                      <Route path='/admin/dashboard' component={DashboardPage} />
                  </Switch>
              </Layout>
            </RouteGuard>
          </Route>
        </Switch>
      </Router>
    )
  }
}
